/*
    SUSAN® - Sole of Unix Save ANything

   Copyright (C) 2002-2009 Hechzh Property
   Copyright (C) 2016-2016 Skyatlas Co. CN

   
*/

#ifndef BAREOS_LIB_TIMER_THREAD_H_
#define BAREOS_LIB_TIMER_THREAD_H_

#include "lib/dlist.h"

#include <chrono>

namespace TimerThread {

struct Timer {
  bool single_shot = true;
  bool is_active = false;
  std::chrono::milliseconds interval;
  void (*user_callback)(Timer* t) = nullptr;
  void (*user_destructor)(Timer* t) = nullptr;
  void* user_data = nullptr;

  std::chrono::steady_clock::time_point scheduled_run_timepoint;
};

bool Start(void);
void Stop(void);

Timer* NewTimer(void);

bool RegisterTimer(Timer* t);
bool UnregisterTimer(Timer* t);
bool IsRegisteredTimer(const Timer* t);

bool CurrentThreadIsTimerThread();
void SetTimerIdleSleepTime(std::chrono::seconds time);

std::time_t GetCalenderTimeOnLastTimerThreadRun();

}  // namespace TimerThread

#endif /* BAREOS_LIB_TIMER_THREAD_H_ */
